package com.dashu.device.util;


import com.dashu.base.bean.device.HF.req.HFReqOnline;
import com.dashu.base.bean.device.HF.resp.HFRespOnline;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class HFWriteUtil {


    public static void send(ChannelHandlerContext ctx, String msg) {
//        System.out.println(msg);
//         ctx.channel().writeAndFlush(msg);
        ctx.writeAndFlush(new TextWebSocketFrame(Unpooled.copiedBuffer(msg + "\n", CharsetUtil.UTF_8))).addListener((ChannelFutureListener) channelFuture -> {
            if (channelFuture.isDone() && channelFuture.isSuccess()) {
                System.out.println("Send:发送数据到终端成功");
                System.out.println(msg);
            } else {
                System.out.println("Send:发送数据到终端失败");
            }
        });
    }
}
